package Utils;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @author DJJ_F
 * @version 1.0
 * @date 2024/12/05
 * @description 自定义的调用处理器对象
 * 专门用来编写功能增强的代码
 * 只用写一个，代码复用
 */
public class MyInvocationHandler implements InvocationHandler {
    private Object target;

    public MyInvocationHandler(Object target) {
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        long begin = System.currentTimeMillis();
        // 通过反射机制调用目标方法
        Object value = method.invoke(target, args);
        long end = System.currentTimeMillis();
        System.out.println("耗时：" + (end - begin) + "毫秒");
        return value;
    }
}
